/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * <p>Project: javase - Date3
 * <p>Powered by webrx On 2021-11-23 14:52:18
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Date3 {
    public static void main(String[] args) {
        //java 10
        var d = Calendar.getInstance();
        //System.out.printf("%1$tF %1$tT %1$tA%n",d);
        //时间一 1985-10-20 18:06:23
        //时间二 now

        long t2 = d.getTimeInMillis();

        d.set(Calendar.YEAR, 2021);
        d.set(Calendar.MONTH, 11 - 1);
        d.set(Calendar.DAY_OF_MONTH, 22);
        d.set(Calendar.HOUR_OF_DAY, 0);
        d.set(Calendar.MINUTE, 0);
        d.set(Calendar.SECOND, 0);
        //System.out.printf("%1$tF %1$tT %1$tA%n",d);
        long t1 = d.getTimeInMillis();

        //3万天 （13182)
        System.out.println((t2 - t1) / (1000 * 60 * 60 * 24));

        var c = Calendar.getInstance();
        //7天前日期
        c.add(Calendar.DAY_OF_MONTH, -7);
        System.out.printf("%1$tF %1$tT %1$tA%n", c);

        //7天后日期
        c.add(Calendar.DAY_OF_MONTH, 14);
        System.out.printf("%1$tF %1$tT %1$tA%n", c);
        //当前月第一天
        c.set(Calendar.DAY_OF_MONTH, 1);
        System.out.printf("%1$tF %1$tT %1$tA%n", c);

        //当前月最后一天
        c.set(Calendar.MONTH, c.get(Calendar.MONTH) + 1);
        c.set(Calendar.DAY_OF_MONTH, 0);
        System.out.printf("%1$tF %1$tT %1$tA%n", c);


        //1790-01-01 08:00:00
        var dd = new Date(0);
        var sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println(sdf.format(dd));

        //9999-12-31 23:59:59
        var md = new Date(9999 - 1900, 12 - 1, 31, 23, 59, 59);
        System.out.println(sdf.format(md));

        //System.currentTimeMillis() long
    }
}
